package com.example.rpc.service.impl;

import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext;
import com.alipay.common.tracer.core.context.trace.SofaTraceContext;
import com.alipay.common.tracer.core.holder.SofaTraceContextHolder;
import com.alipay.common.tracer.core.span.SofaTracerSpan;
import com.example.rpc.service.HelloService;

import cn.hutool.json.JSONUtil;

/**
 * Quick Start demo implement
 */
public class HelloServiceImpl implements HelloService {
    @Override
    public String sayHello(String string) {
    	
    	SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext();
    	SofaTracerSpan currentSpan = sofaTraceContext.getCurrentSpan();
    	SofaTracerSpanContext sofaTracerSpanContext = currentSpan.getSofaTracerSpanContext();
    	
    	String traceId = sofaTracerSpanContext.getTraceId();
    	String spanId = sofaTracerSpanContext.getSpanId();

    	currentSpan.getBaggageItem("");//获取透传数据
    	
        System.out.println("Server receive: " + string);
        System.err.println(JSONUtil.toJsonStr(currentSpan));
        return "hello " + string + " ！";
    }
}